
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String serverPath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	Date date = new Date();
	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
	String dateString = formatter.format(date);
	request.setAttribute("dateString", dateString);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>
<%
if ("0".equals(request.getParameter("operateType"))) {
%>
编辑原始记录
<%
} else {
%>
查看原始记录
<%
}
%>
</title>
<%@ include file="../jslib/jquerylib.jsp" %>
	<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <%
    request.setAttribute("pageContext", pageContext);
    %>
    <script  type="text/javascript" charset="gbk">
        // 初始化控件
        var TANGER_OCX;
        var itemList1 = "";
        var itemList2 = "";
        var itemList3 = "";
        var jsonarray = "";   
        var rangeName = "A1";
        var colName = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z","AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP", "AQ", "AR", "AS", "AT", "AU", "AV", "AW", "AX", "AY", "AZ","BA", "BB", "BC", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BK", "BL", "BM", "BN", "BO", "BP", "BQ", "BR", "BS", "BT", "BU", "BV", "BW", "BX", "BY", "BZ");    
         
        var allids = '<%=request.getParameter("ids")%>';
        function pageload() {
            TANGER_OCX = document.all("TANGER_OCX");
          
            $.get("<%=request.getContextPath()%>/codeReviewActionNew!getYsjlfilename.action?ids="+allids+"&taskid=<%=request.getParameter("taskId")%>&operateType=<%=request.getParameter("operateType")%>",function(data){
                var sss='${oruUrl}';
            	var values =  {'path':'${oruUrl}'};
            //	var values =  {'path':'e:/test.xls'};
            	
              //  var values = eval('(' + data + ')');
              	if(values.path!= null && values.path!=""){
              	     $("#filepath").val(values.path);
              		TANGER_OCX.BeginOpenFromURL("<%=request.getContextPath()%>/codeReviewActionNew!getTaskFileDownloadYsjlHgz.action?allpath="+values.path);
              	}else{
              		TANGER_OCX.CreateNew("Excel.Sheet");
              	}
				
	            TANGER_OCX.FileNew = false;//设置新建菜单
				TANGER_OCX.FileOpen = true; //设置打开菜单
				TANGER_OCX.FileClose = false; //设置关闭菜单
				TANGER_OCX.FileSave = false; //设置保存菜单
				TANGER_OCX.FileSaveAs = false; //设置另存菜单
				TANGER_OCX.FilePrint = true; //设置打印菜单
				TANGER_OCX.FilePrintPreview = true; //设置打印预览菜单
				TANGER_OCX.FilePageSetup = true; //设置打印设置菜单
				TANGER_OCX.FileProperties = true; //设置属性菜单
				TANGER_OCX.Toolbars = false;
				
			});
        }
        
        
		function unloadFile(){
			TANGER_OCX.Close();
		}
		window.onbeforeunload = function() {
		    var operateType = <%=request.getParameter("operateType")%>;
		    if(document.body.clientWidth-event.clientX< 170&&event.clientY< 0||event.altKey) {
		        if($("#filename").val()!=''&&operateType=='0'){ 
		　　       return "填写的原始记录单还未保存,是否关闭?"; 
	            }
		    }
		} 
		
      
		function btnClose(){
		    var operateType = <%=request.getParameter("operateType")%>;
		    if($("#filename").val()!=''&&operateType=='0'){ 
		      if(!confirm("填写的原始记录单还未保存,是否关闭?")){
		        return false;
		      }
		    }
			TANGER_OCX.Close();
			window.close();
		}
		//往标签里写值
        function setvalue(key, value) {
           try
           {
           	  
             TANGER_OCX.ActiveDocument.Sheets(1).Range(key).Value = value;
           }
           catch(err)
           {
              
           }
        }
        
		function SaveExcel()
		{
		
         var returnValue =  TANGER_OCX.SaveToURL("<%=basePath%>/workflow/saveYsjld.jsp?flag=0&taskid=<%=request.getParameter("taskId")%>&filename="+$("#filename").val(), "EDITFILE", "", "newexcel.xlsx", 0);
         if(returnValue=='failed'&&returnValue!=''){
           alert("文件上传失败!");
           changeButtonDisabled();   //取消按钮置灰功能
         }else{
             $("#filepath").val(returnValue);
             var params = {
                          "filemodeId":$("#filemodeId").val(),
                          "modetype":$("#modetype").val(),
                          "taskId":'<%=request.getParameter("taskId")%>',
                          "ysjlpath":returnValue,
                          "type":0,
                          "ids":'<%=request.getParameter("ids")%>'
                          }
              
             var actionUrl = '<%=request.getContextPath()%>/codeReviewActionNew!saveysjld.action';  
			 $.ajax({  
			        url : actionUrl,  
			        type : "post", 
			        data:params,
			        dataType : "json",  
			        cache : false,  
			 error : function(textStatus, errorThrown) {  
			        alert("系统ajax交互错误: " + textStatus.value); 
			        changeButtonDisabled();   //取消按钮置灰功能 
		    },  
		    success : function(data, textStatus) {
		        if(data.ajaxResult=='success'){ 
		              window.returnValue = returnValue;     
				      alert("文件上传成功");
				      window.close();
                }else{
                    alert("原始记录单保存失败!");
                    changeButtonDisabled();   //取消按钮置灰功能
                }
		    }    
			});
         
         }
         
       } 
		 function checkexist(key) {
            try {
                var temp = TANGER_OCX.ActiveDocument.Sheets(1).Range(key);
                return true;
            }
            catch (err) {
                return false;
            }
        }

		function getvaluebykey(key){
			try
           {
			return TANGER_OCX.ActiveDocument.Sheets(1).Range(key).Value;
			}
            catch (err) {
                return '';
            }
		}
		//获得单元格的列
		function getRowNum(address) {
          return address.replace(/[^a-z|A-Z]/ig,"");
        }
        //获得单元格的行号
        function getLetter(address) {
            return address.replace(/[^0-9]/ig,"");
        }
		function getColumnindex(column){
			for (var i = 0; i < colName.length; i++) {
                if (colName[i] == column) {
                    return i + 1;
                }
            }
		}
		//根据标签名称获得行或者列
		function getRowOrColumn(bianqian,flag){
		   var val ='';
		   try{
		        var temp  = ""+TANGER_OCX.ActiveDocument.Sheets(1).Range(bianqian).Name; 
		        if(temp!=undefined){
		            var tempTalbe =  temp.split('$');
			        if(flag=='0'){
			          val = tempTalbe[1];  //获得列
			        }else if(flag=='1'){
			          val = parseInt(tempTalbe[2]); //获得行
			        }
		        }
		    }catch(err){
		    }
		    return val; 
		}
		//获得标签对应的值
		function getValueByBiaoqian(biaoqian){
		   var values ='';
		   try{
                values  = TANGER_OCX.ActiveDocument.Sheets(1).Range(biaoqian).Value; 
                values = $.trim(values);
             }catch(err){
             }
           return values;
		}
		var proname = "";
		var rowflag = -1;
		var colflag = -1;
        function selectrangename(row, col) {
        	if (rowflag==row&&colflag==col){
        		return;
        	}
        	else{
        		rowflag = row;
        		colflag = col;
        	}
            if (col <= 256) {
                if (col <= 26) {
                    rangeName = colName[col - 1] + row;
                } else if (col % 26 == 0) {
                    rangeName = String.fromCharCode(65 + (col / 26) - 2) + 'Z' + row;
                } else {
                    rangeName = String.fromCharCode(65 + (col / 26) - 1) + String.fromCharCode(65 + (col % 26) - 1) + row;
                }
            } else {
                rangeName = "";
                alert("列长不能超过256列!");
            }
            try{
            	if (rangeName==proname)
            	{
            		return;
            	}
                var stag = TANGER_OCX.ActiveDocument.Sheets(1).Range(rangeName).Name.Name;
                var operateType = <%=request.getParameter("operateType")%>;
                var biaoqian = "";
                if(operateType=='0'&&dianziqianmType=='1'){
                   if(stag=='试验者'){
                     biaoqian = '试验者';                //试验员电子签名
                   }
                   if(stag=='试验日期'){
                       setvalue(stag,'${dateString}'); 
                   }
                }else if(operateType=='1'&&dianziqianmType=='2'){
                    if(stag=='校对者'){
                        biaoqian = '校对者';             //校对人电子签名
                    }
                    if(stag=='校对日期'){
                      TANGER_OCX.SetReadOnly(false);
                      setvalue(stag,'${dateString}'); 
                      TANGER_OCX.SetReadOnly(true);
                   }
                }
                if(biaoqian!=''){
                    if(operateType=='1'&&dianziqianmType=='2'){
                       TANGER_OCX.SetReadOnly(false);
                    }
                    if('${sessionScope.TDM_USER.signAddress}'!=''){
	                     var path = '${sessionScope.TDM_USER.signAddress}';
	                     setvalue(biaoqian,'');
	         // //         TANGER_OCX.IsShowNetErrorMsg=false;
	                     try{
		           		   TANGER_OCX.AddPicFromURL("<%=request.getContextPath()%>/codeReviewActionNew!getKnowledgeFileDownload.action?allpath="+encodeURIComponent(encodeURIComponent(path)), true, 0, 0, 1, 20, 1); 
			             }catch(err){
			               setvalue(biaoqian,'${sessionScope.TDM_USER.username}');
			             }
			        }else{
		               setvalue(biaoqian,'${sessionScope.TDM_USER.username}');
		            }
		            $("#sfqianming").val('0');
		            if(operateType=='1'&&dianziqianmType=='2'){
		              TANGER_OCX.SetReadOnly(true);
		            }
                }
                
            } 
             catch(err)
            {
                proname="";
            }
          }
        
          
          //选择模版
		function selectModel()
		{
		      var url = "<%=request.getContextPath()%>/workflow/selectFileMode.jsp?temp="+Math.round(Math.random()*10000);
	          var  array = window.showModalDialog(url,null,"dialogHeight:500px;dialogWidth:900px;scroll:no");
	          if(typeof(array) == "undefined"){
				return false;
			  }else{
			      array = eval('('+array +')');
			      $("#filename").val(array.name);
			      $("#modetype").val(array.modetype);
			      $("#filemodeId").val(array.id);
			      TANGER_OCX.OpenFromURL("<%=request.getContextPath()%>/codeReviewActionNew!getTaskFileDownloadYsjlHgz.action?path="+array.path+"&type=ysjlmb");  
	          }
	  }	
	   
       
     //防止表单重复提交
	 function buttonDisabled()
		{	
		for (i = 0;i < document.all.length; i++)
		{
		if (document.all[i].type == 'button' || document.all[i].type == 'submit' || document.all[i].type == 'reset')
		{
		document.all[i].disabled = true;
		}
		}	
    }
    //取消按钮置灰
	 function changeButtonDisabled()
		{	
		for (i = 0;i < document.all.length; i++)
		{
		if (document.all[i].type == 'button' || document.all[i].type == 'submit' || document.all[i].type == 'reset')
		{
		document.all[i].disabled = false;
		}
		}	
    }
    </script>
</head>
<body onload="pageload()" onunload="unloadFile()">

	<table>
		<tr>
			
			    <% if ("txysjl".equals(request.getParameter("stateid"))) 
			     {
			   %>
				<td style='font-size:12pt;color:red'>&nbsp;&nbsp;&nbsp;选择原始记录：</td>
				<td>
					<input type='text' style="width: 200px;"  maxlength="50"  id='filename' name="filename" value='${fileModeName}' readonly="readonly" />
					<span id="selectMode">
					  <img src="<%=request.getContextPath()%>/web/images/form_icon_1.gif" style="cursor: hand" align="absmiddle" title="选择" onclick="selectModel()"></img>
				   </span>
				</td>
				<td style="padding-left:20px;">
					<input type="button"  value="确 定" onclick="SaveExcel()"/>
				</td>
				<%
				}
				 %>
				<td>
					<input type="button"  value="关 闭" onclick="btnClose()"/>
				</td>
				<input type="hidden" id="filepath" name="filepath" value=""/>
				<input type="hidden" id="modetype" name="modetype" value=""/>
				<input type="hidden" id="filemodeId" name="filemodeId" value=""/>
		</tr>
	</table>
	<table>
		<tr>
			<td>
				<div style="width:1050px;height:500px" id="ocxDiv">
    		        <object id="TANGER_OCX" classid="clsid:C9BC4DFF-4248-4a3c-8A49-63A7D317F404" 
	                codebase="<%=basePath%>OfficeControl.cab#version=5,0,1,8" width="100%" height="700">
	                <param name="MakerCaption" value="北京天健通泰科技有限公司">
	                <param name="MakerKey" value="458CA98356A147C9E15250F8AA371CEAD3DD141E">
	                <param name="ProductCaption" value="原始记录录入"> 
	                <param name="ProductKey" value="72FF4EC5A7340418D893A95BC31C4ABDE026331D">
	                <SPAN STYLE="color:red">该网页需要控件浏览.浏览器无法装载所需要的文档控件.请检查浏览器选项中的安全设置.</SPAN>
	                </object>
    			</div>	
			</td>
		</tr>
	</table>
</body>
<SCRIPT language="JScript" for="TANGER_OCX" event="OnSheetSelectionChange(SheetName, row, col)">
        selectrangename(row, col);
</SCRIPT>
<SCRIPT language="JScript" for="TANGER_OCX" event="AfterOpenFromURL(doc)">
     
</SCRIPT>
</html>